home *** CD-ROM | disk | FTP | other *** search
- {$L-,D-}
-
- unit CommWells;
-
- interface
-
- uses Command, Shape, MSGraph;
-
- const
-
- MAXCOMMWELLITEMS = 25;
-
- type
-
- CommWell = object
- mh, mw : word; { menu button height and width }
- color : word; { color of command items }
- NumItems : word;
- SelItem : word;
- Menu : array[1..MAXCOMMWELLITEMS] of Command;
- procedure Initialize( mh, mw, color : word);
- procedure SelectItem( w : word);
- function SelectedItem : word;
- procedure AddCommand( s : Shape; f : CommandProc);
- procedure Draw;
- procedure Erase;
- function PtInRegion( px, py : word) : boolean;
- procedure Process( px, py : word);
- end;
-
- implementation
-
- procedure CommWell.Initialize( mh, mw, color : word);
- begin
- self.NumItems := 0;
- self.mh := mh;
- self.mw := mw;
- self.color := color;
- self.SelItem := 0;
- end;
-
- procedure CommWell.AddCommand( s : Shape; f : CommandProc);
- var
- y : word;
- c : Command;
- begin
- new(c);
- with self do begin
- y := NumItems * mh;
- c.Initialize( 0, y, mw, mh, color, TRUE, s);
- c.SetProc( f );
- inc( NumItems );
- self.Menu[NumItems] := c;
- inc( y, mh);
- end;
- end;
-
- procedure CommWell.SelectItem( w : word);
- begin
- with self do begin
- if SelItem<>0 then Menu[SelItem].UnSelect;
- SelItem := w;
- if w<>0 then Menu[w].Select;
- end;
- end;
-
- function CommWell.SelectedItem : word;
- begin
- SelectedItem := self.SelItem;
- end;
-
- procedure CommWell.Draw;
- var
- n : word;
- begin
- with self do begin
- for n := 1 to NumItems do Menu[n].draw;
- if SelItem<>0 then Menu[SelItem].Select;
- end;
- end;
-
- procedure CommWell.Erase;
- begin
- with self do begin
- if SelItem<>0 then Menu[SelItem].UnSelect;
- _SetColor(0);
- _Rectangle( _GFILLINTERIOR, 0, 0, mw, NumItems*mh);
- end;
- end;
-
- function CommWell.PtInRegion( px, py : word) : boolean;
- begin
- with self do
- PtInRegion := (px <= mw) and (py <= (NumItems*mh));
- end;
-
- procedure CommWell.Process( px, py : word );
- var
- i : word;
- begin
- i := (py div self.mh) + 1;
- self.SelectItem( i );
- self.Menu[ i ].DoIt;
- end;
-
- begin
- end.
-
-